fix: path when genesis file already exists.#2361
Conversation
WalkthroughThe changes introduce a new utility function to construct the path to the genesis file based on a given home directory. This function is then used in multiple initialization commands to ensure consistent and explicit handling of the genesis file path, replacing previous direct uses of the home directory path. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI_Init_Command
participant GenesisPkg
User->>CLI_Init_Command: Run initialization
CLI_Init_Command->>GenesisPkg: GenesisPath(homePath)
GenesisPkg-->>CLI_Init_Command: Return genesis file path
CLI_Init_Command->>GenesisPkg: LoadGenesis(genesisPath)
GenesisPkg-->>CLI_Init_Command: Genesis data or error
CLI_Init_Command->>User: Print status/logs using genesisPath
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
pkg/genesis/io.go (1)
23-25: Consider using the newGenesisPathfunction for consistency.The
CreateGenesisfunction manually constructs the genesis path, but it could use the newly introducedGenesisPathfunction for consistency.Apply this diff to use the centralized path construction:
- configDir := filepath.Join(homePath, "config") - genesisPath := filepath.Join(configDir, "genesis.json") + genesisPath := GenesisPath(homePath) + configDir := filepath.Dir(genesisPath)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/evm/based/cmd/init.go(1 hunks)apps/evm/single/cmd/init.go(1 hunks)apps/testapp/cmd/init.go(1 hunks)pkg/genesis/io.go(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/evm/based/cmd/init.go (1)
pkg/genesis/io.go (3)
GenesisPath(14-17)ErrGenesisExists(11-11)LoadGenesis(54-76)
apps/evm/single/cmd/init.go (1)
pkg/genesis/io.go (3)
GenesisPath(14-17)ErrGenesisExists(11-11)LoadGenesis(54-76)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Summary
🔇 Additional comments (6)
pkg/genesis/io.go (1)
13-17: Good addition for centralizing genesis path logic.The new
GenesisPathfunction properly encapsulates the logic for constructing the genesis file path from a home directory.apps/testapp/cmd/init.go (3)
65-65: Good fix for explicit genesis file path handling.Using
GenesisPathto get the actual genesis file path instead of using the home directory path directly is the correct approach.
68-68: Correctly fixes the LoadGenesis path parameter.This change fixes a bug where
LoadGenesiswas being called withhomePath(a directory) instead of the actual genesis file path. According to theLoadGenesisfunction signature inpkg/genesis/io.go(lines 54-76), it expects a file path, not a directory path.
76-76: Improved user feedback with specific file path.The printf statement now shows the exact genesis file path instead of just the home directory, providing clearer information to the user.
apps/evm/single/cmd/init.go (1)
65-76: Consistent implementation of genesis path fix.The changes follow the same pattern as in
apps/testapp/cmd/init.go, correctly using the newGenesisPathfunction to get the actual genesis file path instead of passing the home directory toLoadGenesis. This ensures consistency across all init commands and fixes the path handling bug.apps/evm/based/cmd/init.go (1)
65-76: Excellent consistency in fixing the genesis path issue.The implementation mirrors the changes in the other init commands (
apps/testapp/cmd/init.goandapps/evm/single/cmd/init.go), ensuring uniform handling of genesis file paths across all initialization commands. This systematic approach fixes the bug whereLoadGenesiswas incorrectly receiving directory paths instead of file paths.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2361 +/- ##
==========================================
- Coverage 69.64% 69.57% -0.07%
==========================================
Files 64 64
Lines 6190 6193 +3
==========================================
- Hits 4311 4309 -2
- Misses 1486 1491 +5
Partials 393 393 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix incorrect use of
homePathfor genesis file path.Summary by CodeRabbit